package io.renren.ik;

import io.renren.RenrenApplication;
import io.renren.common.vo.TokenVo;
import io.renren.config.BizConfig;
import io.renren.modules.avanotes.service.TokenAnalyzerService;
import lombok.extern.slf4j.Slf4j;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.wltea.analyzer.cfg.Configuration;
import org.wltea.analyzer.lucene.IKAnalyzer;

import java.io.IOException;
import java.io.StringReader;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: xiaomi
 * @date: 2022/2/16
 * @description:
 *
 * 使用 elasticsearch-analysis-ik-8.0.0 太麻烦了，于是改为 IKAnalyzer2012_u6 + lucene 3.6
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = RenrenApplication.class)
@Slf4j
public class Tokenizer {

    @Autowired
    @Qualifier(BizConfig.IMPL_IK_ANALYZER_SMART)
    TokenAnalyzerService tokenAnalyzerService;

    @Test
    public void testToken() throws IOException {
        String word = "8月17日，“雄鹰突击-2018”中国和白俄罗斯特种部队联合训练，在北部战区陆军某综合训练基地完成综合演练并举行结训仪式。北部战区副司令员兼北部战区陆军司令员王印芳、白俄罗斯武装力量总参谋长兼国防部第一副部长别洛科涅夫出席结训仪式。";
        List<TokenVo> tokens = tokenAnalyzerService.token(word);
        log.info(tokens.toString());
    }


}
